package code
{
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	
	public class OutDisplay extends EventDispatcher
	{
		//保存所有对象
		private var objAr:Array;
		//保存侦听类型
		private var type:String;
		
		//构造函数
		public function OutDisplay(_type:String,dis:DisplayObject,...objs){
			type = _type;
			objAr = objs;
			dis.addEventListener(_type,fun);
		}
		
		//事件处理
		private function fun(e:Event):void{
			for(var i:uint = 0;i<objAr.length;i++){
				if(e.target == objAr[i]) return;
				if(objAr[i] is DisplayObjectContainer){
					if(objAr[i].contains(e.target)) return;
				} 
			}
			e.currentTarget.removeEventListener(type,fun);
			dispatchEvent(new Event(Event.CANCEL));
		}
	}
}